/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package businessDelegates;

import businessObjects.Admin;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import sessionFacades.AdminFacadeRemote;

/**
 *
 * @author williamprado
 */
@EJB(name="adminfr", beanInterface = AdminFacadeRemote.class)
public class AdminBusinessDelegate {
    
    //@EJB
    //private AdminFacadeRemote adminFacadeBean;

    

    //@Resource SessionContext sessionContext;

    //AdminFacadeRemote adminFacadeBean = (AdminFacadeRemote) sessionContext.lookup("ejb/AdminFacade");

    public AdminBusinessDelegate(){

    }

    public void registrarAdmin(Admin admin){        
        try {
            Context ctx = new InitialContext();
            AdminFacadeRemote adminFacadeBean = (AdminFacadeRemote) ctx.lookup("java:comp/env/adminfr");
            adminFacadeBean.registrarAdmin(admin);
        } catch (NamingException ex) {
            Logger.getLogger(AdminBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Admin login(String login, String pass){
        try {
            Context ctx = new InitialContext();
            AdminFacadeRemote adminFacadeBean = (AdminFacadeRemote) ctx.lookup("java:comp/env/adminfr");
            Admin ad = adminFacadeBean.login(login, pass);
            return ad;
        } catch (NamingException ex) {
            Logger.getLogger(AdminBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public void actualizarAdmin(Admin admin){
        try {
            Context context = new InitialContext();
            AdminFacadeRemote adminFacadeBean = (AdminFacadeRemote) context.lookup("java:comp/env/adminfr");
            adminFacadeBean.actualizarAdmin(admin);
        } catch (NamingException ex) {
            Logger.getLogger(AdminBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void eliminarAdmin(String login){
        try {
            Context context = new InitialContext();
            AdminFacadeRemote adminFacadeBean = (AdminFacadeRemote) context.lookup("java:comp/env/adminfr");
            adminFacadeBean.eliminarAdmin(login);
        } catch (NamingException ex) {
            Logger.getLogger(AdminBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public int getBasicRowsParam(){
        int rows = 1;
        try {
            Context context = new InitialContext();
            AdminFacadeRemote adminFacadeBean = (AdminFacadeRemote) context.lookup("java:comp/env/adminfr");
            rows = adminFacadeBean.getBasicRowsParam();
        } catch (NamingException ex) {
            Logger.getLogger(AdminBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
        return rows;
    }

    public void setBasicRowsParam(int rows){
        try {
            Context context = new InitialContext();
            AdminFacadeRemote adminFacadeBean = (AdminFacadeRemote) context.lookup("java:comp/env/adminfr");
            adminFacadeBean.setBasicRowsParam(rows);
        } catch (NamingException ex) {
            Logger.getLogger(AdminBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
